package com.bianpai.core;

import java.util.HashMap;
import java.util.Map;

/**
 * 节点执行结果
 */
public class NodeResult {
    private boolean success;
    private String message;
    private Map<String, Object> data;
    private Throwable exception;
    
    public NodeResult() {
        this.data = new HashMap<>();
    }
    
    public static NodeResult success() {
        NodeResult result = new NodeResult();
        result.success = true;
        result.message = "Success";
        return result;
    }
    
    public static NodeResult success(String message) {
        NodeResult result = new NodeResult();
        result.success = true;
        result.message = message;
        return result;
    }
    
    public static NodeResult success(String message, Map<String, Object> data) {
        NodeResult result = new NodeResult();
        result.success = true;
        result.message = message;
        result.data = data;
        return result;
    }
    
    public static NodeResult failure(String message) {
        NodeResult result = new NodeResult();
        result.success = false;
        result.message = message;
        return result;
    }
    
    public static NodeResult failure(String message, Throwable exception) {
        NodeResult result = new NodeResult();
        result.success = false;
        result.message = message;
        result.exception = exception;
        return result;
    }
    
    public NodeResult addData(String key, Object value) {
        this.data.put(key, value);
        return this;
    }
    
    public boolean isSuccess() {
        return success;
    }
    
    public String getMessage() {
        return message;
    }
    
    public Map<String, Object> getData() {
        return data;
    }
    
    public Throwable getException() {
        return exception;
    }
}